﻿using Kanban.DALContainer;
using Kanban.IBLL;
using Kanban.IDal;
using Kanban.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Kanban.BLL
{
    public class Line_SettingService : BaseService<Line_Setting>, ILine_SettingService
    {
        private readonly ILine_SettingDal Line_SettingDal = Container.Resolve<ILine_SettingDal>();

        public override void SetCurrentDal()
        {
            Dal = Line_SettingDal;
        }

        public async Task<Tuple<IList<object>, int>> GetModelsByPageAsync(string search, int pageSize, int pageIndex)
        {
            return await Line_SettingDal.GetModelsByPageAsync(search, pageSize, pageIndex);
        }

        public async Task<bool> Save(Line_Setting model)
        {
            var query = await GetModelAsync(model.Id);
            if (query == null)
            {
                model.LINENAME = model.LINENAME ?? "";
                model.Memo = model.Memo ?? "";
                model.CreateTime = DateTime.Now;
                return await AddAsync(model) > 0;
            }
            else
            {
                query.LINENAME = model.LINENAME;
                query.Memo = model.Memo;
                query.MAX_QTY = model.MAX_QTY;
                query.暂停叫料 = model.暂停叫料;
                query.IsValid = model.IsValid;
                query.Memo = model.Memo;
                return await UpdateAsync(query) > 0;
            }
        }
    }
}
